package leetcode.code1592;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution4 implements IDebug {

	public String reorderSpaces(String text) {
		int space = (int) text.chars().filter(c -> c == ' ').count();
		String[] words = text.trim().split("\\s+");
		int size = words.length - 1;
		if (size == 0) {
			return words[0] + " ".repeat(space);
		}
		int d = space / size;
		int m = space % size;
		return String.join(" ".repeat(d), words) + " ".repeat(m);
	}

	@Override
	public void debug4() {
		HelpDebug.compare("a   ", this.reorderSpaces("a   "));
		HelpDebug.compare("a b c d  ", this.reorderSpaces("a b   c d"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution4 so = new Solution4();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
